package com.heimao.controller;

import com.heimao.pojo.User;
import jdk.nashorn.internal.objects.NativeJSON;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("/user")
public class UserInfo {
// 访问示例 http://localhost:8080/user/userForm
   @GetMapping("/userForm")
    public String getUser(){
        return "form";
    }
    // 访问示例 http://localhost:8080/user/addUser
    @PostMapping("/addUser")
    public String addUser(User user, Model model){
        model.addAttribute(user);
        System.out.println("=================="+user.getName());
        return "userInfo";
    }
    // 访问示例 http://localhost:8080/user/show?name=黑猫
    @GetMapping("/show")
    public String userPut(@RequestParam("name") String name,Model model){
       model.addAttribute("msg",name);

        return "index";
    }

}
